using System;
using System.Linq.Expressions;

namespace Karma.Framework.Core.Domain.Tools.Import.Configuration.Fluent
{
    public class FluentValuePropertyConfiguration<T, TProperty>
        where TProperty : struct
    {
        protected FluentTransientConfiguration<T> _entityConfiguration;

        public FluentValuePropertyConfiguration(FluentTransientConfiguration<T> eConf, Expression<Func<T, TProperty>> expression)
        {
            if (expression.Body.NodeType != ExpressionType.MemberAccess)
            {
                throw new InvalidOperationException("La expresion para configurar una propiedad debe ser del tipo MemberAccess.");
            }
            var exp = (MemberExpression)expression.Body;
            var member = exp.Member;

            _configuration = new PropertyConfiguration(member.Name, member.ReflectedType);
            _entityConfiguration = eConf;
        }

        protected PropertyConfiguration _configuration;
        public PropertyConfiguration Configuration
        {
            get
            {
                return _configuration;
            }
        }

        public FluentTransientConfiguration<T> Formula(Expression<Func<T, object>> expression)
        {
            //_configuration.Formula = expression;
            return _entityConfiguration;
        }
    }
}